package com.zyzd.baseprojectofvolly;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.zyzd.baseprojectofvolly.chat.DemoHelper;
import com.zyzd.commontools.CommonTools;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


/**
 * Created by 李宗源 on 2017/2/8.
 */

public class MyApplication extends Application {

    public static Context context;


    public static Context getContext() {
        return context;
    }

    /**
     * 获取进程号对应的进程名
     *
     * @param pid 进程号
     * @return 进程名
     */
    private static String getProcessName(int pid) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
            String processName = reader.readLine();
            if (!TextUtils.isEmpty(processName)) {
                processName = processName.trim();
            }
            return processName;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
//        LeakCanary.install(this);
        context = getApplicationContext();
        CommonTools.init(context);

        DemoHelper.getInstance().init(getApplicationContext());//初始化环信
//
//        JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
//        JPushInterface.init(this);            // 初始化 JPush
//
//        ImageUtil.loadHomeBg(this, null);
//        ImageUtil.loadMainBg(this, null);

        //配置bugly
        // 获取当前包名
//        String packageName = context.getPackageName();
//        // 获取当前进程名
//        String processName = getProcessName(android.os.Process.myPid());
//        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
//        strategy.setUploadProcess(processName == null || processName.equals(packageName));
//        CrashReport.initCrashReport(getApplicationContext(), "4dc909ccf0", true, strategy);

    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//        MultiDex.install(this);
    }
}
